package com.wwg.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;

/**
 * 
 *类描述: 金服平台日志工具类
 *
 *@Author:李志雄
 *@date:2019年9月30日
 *@Version:1.0
 */
public class JfptLogUtil {
	
	public static Logger getLogger(Class<?> clazz)
	{
		return LoggerFactory.getLogger(clazz);
	}
	
	public static void debug(Logger logger,String msg)
	{
		if(logger.isDebugEnabled())
		{
			logger.debug(logger.getName() + " : " + msg);
		}
	}
	
	public static void debug(Logger logger,String format, Object... arguments)
	{
		if(logger.isDebugEnabled())
		{
			logger.debug(logger.getName() + " : " + format, arguments);
		}
	}
	
	public static void info(Logger logger, String msg)
	{
		logger.info(msg);
	}
	
	public static void info(Logger logger,String format, Object... arguments)
	{
		logger.info(format, arguments);
	}
	
	public static void error(Logger logger,String msg)
	{
		logger.error(msg);
	}
	
	public static void error(Logger logger,String format, Object... arguments)
	{
		logger.error(format, arguments);
	}

	public static void error(Logger logger, String msg, Throwable t)
	{
		logger.error(msg, t);
	}

	/**
	 * @类描述: 获取堆栈信息
	 * @Author wwg
	 * @Date: 2020/11/12 15:05
	 * @Params [e]
	 * @Return java.lang.String
	 */
	public static String getStatckTrace(Exception e) {
		String stackTrace = null;
		if(e == null){
			return stackTrace;
		}
		try (
				ByteArrayOutputStream baos = new ByteArrayOutputStream();
				PrintWriter pw = new PrintWriter(baos)
		) {
			e.printStackTrace(pw);
			pw.flush();
			stackTrace = baos.toString(StandardCharsets.UTF_8.name());
		} catch (IOException unsupportedEncodingException) {
			unsupportedEncodingException.printStackTrace();
		}
		return stackTrace;
	}
}
